<template>
    <div style="margin: 0px auto">
        <h1>未解决商品问题</h1>
        <template>
            <div style="margin-left: 500px;padding-bottom: 50px">
                <span>条件筛选：</span>
                <el-select v-model="tableDatas.value" placeholder="请选择" @change="querystate()">
                    <el-option
                            v-for="item in tableDatas"
                            :key="item.value"
                            :label="item.name"
                            :value="item.value">
                    </el-option>
                </el-select>
                &nbsp;
                <el-button icon="el-icon-search" @click="buttonClick()" circle></el-button>
                <!--<el-button type="primary" @click="buttonClick()">查询</el-button>-->
            </div>
            <el-table
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        fixed
                        prop="id"
                        label="ID"
                        width="150">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="commodityname"
                        label="商品名称"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="because"
                        label="商品问题"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="jointime"
                        label="日期"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="stock"
                        label="问题商品数量"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="state"
                        label="等待处理（已处理,未处理,不处理）"
                        width="120">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.state">
                            <el-option v-for="s in tableDatas"
                                       :key="s"
                                       :label="s.name"
                                       :value="s.value">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <!--具体操作-->
                    <el-button type="primary" @click="updatestate(scope.row)"  icon="el-icon-edit"
                               circle></el-button>
                    <!--<el-button @click="updatestate(scope.row)" type="text" size="small">修改</el-button>-->
                </template>
            </el-table-column>
            </el-table>
        </template>
    </div>
</template>

<script>
    export default {
        name: "unsolve_issue",
        data() {
            return {
                tableData: [],
                tableDatas: [
                    {
                        name: '未处理',
                        value: 0
                    },
                    {
                        name: '已处理',
                        value: 1
                    }, {
                        name: '不处理',
                        value: 2
                    }],
                value: '',
                storeid: 1,

            }
        },
        methods: {
            updatestate(row) {
                var id = row.id;
                var sta = row.state;
                this.axios.get("/Problem/UpdProblemtoState", {
                    params: {
                        state: sta,
                        id: id
                    }
                }).then(response => {
                    if (response.data == null) {
                        this.$alert("修改失败");
                    } else {
                        this.$alert("修改成功");
                        this.axios.post("/Problem/QueryProblemtoState").then(response => {
                            if (response.data == null) {
                                this.$alert("请求数据为空");
                            } else {
                                this.tableData = response.data;
                            }
                        })
                    }
                })
            },
            querystate() {
                var sta = this.tableDatas.find((item) => {
                    return item.value == this.tableDatas.value;
                });
                this.axios.get("/Problem/QueryProblemtoone", {
                    params: {
                        state: sta.value,
                        storeid: this.storeid
                    }
                }).then(response => {
                    if (response == null) {
                        this.$alert("该条件没有商品");
                    } else {
                        this.tableData = response.data;
                    }
                })
            },
            buttonClick() {
                this.axios.post("/Problem/QueryProblemtoState").then(response => {
                    if (response.data == null) {
                        this.$alert("请求数据为空");
                    } else {
                        this.tableData = response.data;
                    }
                    this.$router.go(0);
                })
            }
        },
        created() {
            this.axios.post("/Problem/QueryProblemtoState").then(response => {
                if (response.data == null) {
                    this.$alert("请求数据为空");
                } else {
                    this.tableData = response.data;
                }
            })
        }
    }
</script>

<style scoped>

</style>